﻿namespace Chain.Wechat
{
    using System;
    using System.Runtime.CompilerServices;
    using System.Xml;

    public class IResponse
    {
        
        private string _CreateTime;
        
        private string _FromUserName;
        
        private string _MsgType;
        
        private IRequest _Request;
        
        private string _ToUserName;
        
        private XmlDocument _XmlDoc;

        protected IResponse(IRequest req)
        {
            this.Request = req;
            this.XmlDoc = new XmlDocument();
            XmlElement xml = this.XmlDoc.CreateElement("xml");
            XmlElement nodeToUserName = this.XmlDoc.CreateElement("ToUserName");
            XmlCDataSection xmlCData = this.XmlDoc.CreateCDataSection(req.FromUserName);
            nodeToUserName.AppendChild(xmlCData);
            xml.AppendChild(nodeToUserName);
            XmlElement nodeFromUserName = this.XmlDoc.CreateElement("FromUserName");
            xmlCData = this.XmlDoc.CreateCDataSection(req.ToUserName);
            nodeFromUserName.AppendChild(xmlCData);
            xml.AppendChild(nodeFromUserName);
            XmlElement nodeCreateTime = this.XmlDoc.CreateElement("CreateTime");
            nodeCreateTime.InnerText = DateTime.Now.Ticks.ToString();
            xml.AppendChild(nodeCreateTime);
            this.XmlDoc.AppendChild(xml);
        }

        public string Result()
        {
            return this.XmlDoc.InnerXml;
        }

        public string CreateTime
        {
            
            get
            {
                return this._CreateTime;
            }
            
            set
            {
                this._CreateTime = value;
            }
        }

        public string FromUserName
        {
            
            get
            {
                return this._FromUserName;
            }
            
            set
            {
                this._FromUserName = value;
            }
        }

        public string MsgType
        {
            
            get
            {
                return this._MsgType;
            }
            
            set
            {
                this._MsgType = value;
            }
        }

        public IRequest Request
        {
            
            get
            {
                return this._Request;
            }
            
            set
            {
                this._Request = value;
            }
        }

        public string ToUserName
        {
            
            get
            {
                return this._ToUserName;
            }
            
            set
            {
                this._ToUserName = value;
            }
        }

        public XmlDocument XmlDoc
        {
            
            get
            {
                return this._XmlDoc;
            }
            
            set
            {
                this._XmlDoc = value;
            }
        }
    }
}

